package com.automobile.controller;

import com.automobile.domain.Announce;
import com.automobile.domain.User;
import com.automobile.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 类的作用
 *
 * @author liujiamiao
 * @email 2544296058@qq.com
 * @date 2020-03-24 16:14
 */
@Controller
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private CollectService collectService;

    @RequestMapping("/save")
    public @ResponseBody int save(@RequestBody Integer announceId){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        collectService.save(user.getId(),announceId);
        return 1;
    }

    @RequestMapping("/deleteAnnounce")
    public @ResponseBody int deleteAnnounce(@RequestBody Integer announceId){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        collectService.deleteCollect(user.getId(),announceId);
        return 1;
    }

    @RequestMapping("/deleteSmart")
    public @ResponseBody int deleteSmart(@RequestBody Integer smartId){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        collectService.deleteCollect2(user.getId(),smartId);
        return 1;
    }

    @RequestMapping("/findCollect")
    public @ResponseBody int findCollect(@RequestBody Integer announceId){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        collectService.findCollect(user.getId(),announceId);
        return 1;
    }


    @RequestMapping("/findCollectByUserId")
    public @ResponseBody Map<String,Object> findCollectByUserId(){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        Map<String, Object> map = collectService.findCollectByUserId(user.getId());
        return map;
    }

}
